"use strict";
cc._RF.push(module, 'f34ac2GGiVOBbG6XlfvgYP4', 'LocalizedSprite');
// src/LocalizedSprite.js

"use strict";

var n = module.exports = {};
var t = module;

var i = require('SpriteFrameSet');

cc.Class({
  "extends": cc.Component,
  editor: {
    executeInEditMode: !0,
    inspector: "packages://i18n/inspector/localized-sprite.js",
    menu: "i18n/LocalizedSprite"
  },
  properties: {
    spriteFrameSet: {
      "default": [],
      type: i
    }
  },
  onLoad: function onLoad() {
    this.fetchRender();
  },
  fetchRender: function fetchRender() {
    var e = this.getComponent(cc.Sprite);
    if (e) return this.sprite = e, void this.updateSprite(window.i18n.curLang);
  },
  getSpriteFrameByLang: function getSpriteFrameByLang(e) {
    for (var t = 0; t < this.spriteFrameSet.length; ++t) {
      if (this.spriteFrameSet[t].language === e) return this.spriteFrameSet[t].spriteFrame;
    }
  },
  updateSprite: function updateSprite(e) {
    if (this.sprite) {
      var t = this.getSpriteFrameByLang(e);
      !t && this.spriteFrameSet[0] && (t = this.spriteFrameSet[0].spriteFrame), this.sprite.spriteFrame = t;
    } else cc.error("Failed to update localized sprite, sprite component is invalid!");
  }
});

cc._RF.pop();